"""
@author: xxw
@file: 02.类的使用.py
@time: 2023/4/13 10:57
"""
# 类的定义方式
class A:
    pass
class A():
    pass
class B(A): #定义一个子类B，继承父类A的一切属性和方法
    pass

class ATM():
    # 类属性 -- 变量
    info = "银行ATM存取款机"
    country = "中国"
    total_balance = 50000

    def store_money(self, balance):
        self.total_balance += balance
        print(f"存款成功!total_balance is {self.total_balance}")
#查看类空间
print(ATM.__dict__)   #以字典的形式存储
print(f"ATM id :{id(ATM)}")
# 实例化
a1 = ATM()

print(f"before a1 balance is {a1.total_balance}")
print(f"before a1.dict is {a1.__dict__}")

a1.store_money(4000)
print(f"a2.info is {a1.info},a1 id:{id(a1)}")

a2 = ATM()
print(f"a2.info is {a2.info},a2 id:{id(a2)}")

# 设置属性  -- 实例属性
a2.bank = "建设银行"
a2.area = "湖南"
# 修改
a1.country = "china"
print(f"a1.area is {a1.country}")
print(f"a2.bank is {a2.bank}")

print(f"a1.__dict__ is {a1.__dict__}")
print(f"a2.__dict__ is {a2.__dict__}")

##############属性或方法的查找#############
# 1、先在当前空间查找
# 2、当前空间找不到，再通过类对象指证去类空间查找
# 3、类空间没有，就去父类空间查找
# 4、对象可以通过类对象指证访问类空间，但是无法通过对象名修改类空间属性的